package com.frxuexi.park2305.notice

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.frxuexi.lib_base.entity.NoticeBeanItem
import com.frxuexi.lib_base.mvi.BaseActivity
import com.frxuexi.lib_base.mvi.UiState
import com.frxuexi.lib_base.utils.ArouterManager
import com.frxuexi.park2305.R
import com.frxuexi.park2305.databinding.ActivityNoticedDetailBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@Route(path = "/app/NoticedDetailActivity")
@AndroidEntryPoint
class NoticedDetailActivity : BaseActivity<ActivityNoticedDetailBinding,NoticeIntent,NoticeViewModel>() {
    override val binding: ActivityNoticedDetailBinding by lazy { ActivityNoticedDetailBinding.inflate(layoutInflater) }
    override val vm: NoticeViewModel by viewModels<NoticeViewModel>()

    @JvmField
    @Autowired
    var id:Int?=-1
    override fun initData() {
        lifecycleScope.launch {
            vm.uiState.collect{
                when(it){
                    is UiState.onSuccess<*> ->{
                        val item = it.data as NoticeBeanItem
                        binding.bean=item

                    }

                    else -> {}
                }
            }
        }
    }

    override fun initView() {
        id = intent.extras?.getInt("id", -1)
        Log.i("lr",id.toString())
        vm.sendIntent(NoticeIntent.getNoticeById(id!!))


    }

    override fun onPause() {
        super.onPause()
        ArouterManager.nav(this,"/app/NoticeActivity")
    }

}